﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web.UI.Design;

namespace TPG.SharePoint.Workflow.Controls.Design
{
    public partial class HtmlPreviewer : Form
    {
        public static void ShowForDesigner(ControlDesigner designer)
        {
            HtmlPreviewer previewer = new HtmlPreviewer();
            DesignerRegionCollection regions = new DesignerRegionCollection(designer);
            previewer.AddItem("__MainContent", designer.GetDesignTimeHtml(regions));
            foreach (DesignerRegion region in regions)
            {
                if (region is EditableDesignerRegion)
                {
                    previewer.AddItem(
                        region.Name, designer.GetEditableDesignerRegionContent((EditableDesignerRegion)region));
                }
            }
            previewer.Show();
        }

        Dictionary<string, string> _regionContent;

        public HtmlPreviewer()
        {
            InitializeComponent();
            _regionContent = new Dictionary<string,string>();
        }

        public void AddItem(string regionName, string content)
        {
            _regionContent.Add(regionName, content);
            listBox1.Items.Add(regionName);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string content = null;
            if (listBox1.SelectedIndex > -1)
            {
                content = _regionContent[(string)listBox1.SelectedItem];
            }
            textBox1.Text = content;
        }
    }
}
